// pages/distribut/opinion/opinion.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		url: setting.url,
		"opinion": {},
		type: 0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		if (options.type) {
			this.setData({
				type: options.type
			});
		}
		// this.requestMyStore();
	},
	requestMyOpinion: function() {
		var that = this;
		request.get('/api/user/feedback', {
			success: function(res) {
				that.setData({
					opinion: res.data.result
				});
			},
			failStatus: function() {
				return false;
			}
		});
	},

	submitOpinion: function(e) {
		var that = this;
		var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
		var data = Object.assign(e.detail.value, {
			img_file: this.data.opinion.message_img,type:this.data.type
		});
		if (data.msg_content.replace(/\s+/g, '') == "") {
			return app.showTextWarining("请输入具体描述");
		} else if (data.mobile.replace(/\s+/g, '') == "") {
			return app.showTextWarining("请输入手机号");
		} else if (!myreg.test(data.mobile)) {
			return app.showTextWarining("手机号不合法");
		}
		request.post('/api/user/feedback', {
			data: data,
			success: function(res) {
				app.showSuccess(res.data.msg);
				that.setData({
					opinion: res.data.result
				});
				this.timer = setTimeout(() => {
					wx.navigateBack();
				}, 1000)

			}
		});
	},
	changeStoreImg: function() {
		var that = this;
		wx.chooseImage({
			count: 1, //最多1张图片,默认9
			sizeType: ['compressed', 'original'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['camera', 'album'], // 可以指定来源是相册还是相机，默认二者都有
			success: function(res) {
				request.uploadFile('/api/user/upload_comment_img', {
					filePath: res.tempFilePaths[0],
					name: 'img_file',
					success: function(res) {
						that.setData({
							'opinion.message_img': res.data.result
						});
						app.showSuccess("设置成功");
					}
				});
			}
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})